package io.gitee.zhangbinhub.acp.cloud.server.helloworld.component;

import com.alibaba.cloud.nacos.loadbalancer.ServiceInstanceFilter;
import org.jetbrains.annotations.NotNull;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.DefaultRequest;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.cloud.client.loadbalancer.RequestData;
import org.springframework.cloud.client.loadbalancer.RequestDataContext;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class CustomerFilterA implements ServiceInstanceFilter {
    @NotNull
    @Override
    public List<ServiceInstance> filterInstance(@NotNull Request<?> request, @NotNull List<ServiceInstance> serviceInstances) {
        System.out.println(">>>>>>>> CustomerFilterA");
        RequestData requestData = ((RequestDataContext) ((DefaultRequest<?>) request).getContext()).getClientRequest();
        System.out.println(requestData.getHeaders().toString());
        return new ArrayList<>(serviceInstances);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
